package cn.wolfcode.crm.domain;

import com.alibaba.druid.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Setter
@Getter
public class Employee {
    public static final int STATE_NORMAL = 1;//在职
    public static final int STATE_QUIT = 0;//离职

    private Long id;

    private String username;

    private String realname;

    private String password;

    private String tel;

    private String email;

    private Department dept;

    //转换成json格式的日期类型
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    //数据传入使用日期类型
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date hiredate;

    private int admin;

    private int state;

    private List<Role> roles = new ArrayList<>();

    private String imagePath;

    public String getSmallImagePath(){
        if(!StringUtils.isEmpty(imagePath)){
            //根据.来分割字符串需要使用\转义
            String[] split = imagePath.split("\\.");
            System.out.println(Arrays.asList(split));
            //a_smail.jpg
            return split[0]+"_small."+split[1];
        }
        return null;
    }
}